package moyangjia.retailers.uims.config;

/**
 * @description:
 * @author: honglei
 * @time: 2021/3/15 0015 17:27
 */

import moyangjia.retailers.storage.sys.domain.SysUser;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    protected final Log logger = LogFactory.getLog(getClass());

//    @Autowired
//    private UserRepository userRepository;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

        // 根据名称去查数据库
        SysUser clUser = new SysUser();
        clUser.setUserName(username);
        clUser.setPassword("123456");

        // 权限列表
        List<String> user_permission = new ArrayList<>();
        String user_permission_string  = StringUtils.join(user_permission.toArray(), ",");
        user_permission.add("admin");
        return new UserInfo(username, clUser.getPassword(), AuthorityUtils.commaSeparatedStringToAuthorityList(user_permission_string));
    }
}
